/**
 * Created by cqy on 2017/2/17.
 */
define(function (require) {

    /*扩展日期工具类到全局工具中*/
    /**
     * @param date
     * @param format
     * @returns {String}
     */
    var _formatDate = function (date, format) {
        format = format || "yyyy-MM-dd hh:mm:ss";
        var o = {
            "M+": date.getMonth() + 1,  //month
            "d+": date.getDate(),     //day
            "h+": date.getHours(),    //hour
            "m+": date.getMinutes(),  //minute
            "s+": date.getSeconds(), //second
            "q+": Math.floor((date.getMonth() + 3) / 3),  //quarter
            "S": date.getMilliseconds() //millisecond
        }

        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        }

        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    };

    var BaseUtils = function () {

    };
    BaseUtils.prototype.formatDate = _formatDate;
    BaseUtils.prototype.formatTimestamp = function (value, format) {
        var date = new Date(value);
        return _formatDate(date, format);
    };
    BaseUtils.prototype.openNewWindow = function (url, name) {
        var options = 'status=no,menubar=no,scrollbars=no,resizable=yes,toolbar=no,location=no'
            + ',width=' + (screen.availWidth - 10).toString()
            + ',height=' + (screen.availHeight - 122).toString()
            + ',screenX=0,screenY=0,left=0,top=0';
        var win = window.open(url, name, options);
        if (win == null || typeof(win) === "undefined") {
            //alert('')
        }
        win.focus();
        try {
            win.moveTo(0, 0);
        } catch (e) {
            console.log(e);
        }
        win.resizeTo(screen.availWidth, screen.availHeight);
        return win;
    };

    return new BaseUtils();
});